﻿'         This file is Copyright © 2008-2012 Billy O'Neal and Aommaster
'                            All rights reserved.
'
' This file is released under the 2-Clause BSD license, included in LICENSE.TXT
'                           and on the MHWT website
Imports System.Windows.Forms
Imports System.ComponentModel

Class EditSpeechInstance
    Private WithEvents editedInstance As SpeechInstance
    Private Sub populate()
        layoutPanel.Controls.Clear()
        For Each item As Control In editedInstance.Controls
            layoutPanel.Controls.Add(item)
        Next
        Me.Text = "Editing an instance of canned speech: " + editedInstance.ToString
    End Sub
    Private Sub terminate()
        Me.Close()
    End Sub
    Sub New(ByVal instance As SpeechInstance)
        InitializeComponent()
        editedInstance = instance
        AddHandler editedInstance.terminateEditors, AddressOf terminate
        populate()
        Visible = True
        If layoutPanel.Controls.Count = 0 Then
            Me.Visible = False
        End If
    End Sub

    Private Sub editSpeechInstance_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        populate()
    End Sub

    Private Sub editSpeechInstance_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        layoutPanel.Controls.Clear()
        RemoveHandler editedInstance.TerminateEditors, AddressOf terminate
    End Sub
End Class
